package com.yearno.kotlinbaseframe.ui

import android.content.res.Configuration
import android.content.res.Resources
import android.view.Gravity
import android.view.Window
import android.view.WindowManager

import com.yearno.baseframe.base.BaseDialogFragment
import com.yearno.kotlinbaseframe.R

/**
 * 测试横屏弹窗
 */
class TestHoriDialog : BaseDialogFragment() {

    override val layoutId = R.layout.dialog_test_hori

    override val canCancel = true

    override fun setWindowAttributes(window: Window?) {
        val params = window?.attributes
        if(this.resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT){
            // 竖屏
            params?.width = WindowManager.LayoutParams.MATCH_PARENT
            params?.height = (Resources.getSystem().displayMetrics.heightPixels * 0.5f).toInt()
            params?.gravity = Gravity.BOTTOM
            window?.attributes = params
            window?.setWindowAnimations(R.style.Base_Theme_Anim_BottomIn)
        } else {
            // 横屏
            params?.width = (Resources.getSystem().displayMetrics.widthPixels * 0.5f).toInt()
            params?.height = WindowManager.LayoutParams.MATCH_PARENT
            params?.gravity = Gravity.RIGHT
            window?.attributes = params
            window?.setWindowAnimations(R.style.Base_Theme_Anim_RightIn)
        }
        //        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        window?.setDimAmount(0f)
    }

}